import {Sprite} from "../base/Sprite.js";
import {DataStore} from "../base/DataStore.js";
import {Director} from "../Director.js";


export class Land extends Sprite {
    constructor() {
        let image = DataStore.getInstance().resLoaded.get('land');
        super(image, 0, 0, image.width, image.height
            , 0, DataStore.getInstance().canvas.height - image.height, image.width, image.height);
        this.landX = 0;
        this.landSpeed = Director.getInstance().speed;
    }

    draw(img = this.img, srcX = this.srcX, srcY = this.srcY, srcW = this.srcW, srcH = this.srcH, x = this.x, y = this.y, width = this.width, height = this.height) {
        this.landX += this.landSpeed;
        super.draw(img, srcX, srcY, srcW, srcH, -this.landX, y, width, height);
        super.draw(img, srcX, srcY, srcW, srcH,  DataStore.getInstance().canvas.width-this.landX, y, width, height);

        if(this.landX > DataStore.getInstance().canvas.width) {
            this.landX = 0;
        }

    }
}